package com.qeado.content.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qeado.content.dao.CollegeInfoDao;
import com.qeado.content.model.CollegeInfo;
import com.qeado.content.service.CollegeInfoService;

@Service
public class CollegeInfoServiceImpl implements CollegeInfoService {
	@Autowired
	private CollegeInfoDao collegeInfoDao;

	@Override
	public void deleteColleage(String id) {
		collegeInfoDao.deleteColleage(id);
	}

	@Override
	public List<CollegeInfo> getColleageCategoryList() {
		return collegeInfoDao.getColleageCategoryList();
	}

	@Override
	public CollegeInfo getCollegeLogoById(String id) {
		return collegeInfoDao.getCollegeLogoById(id);
	}

	@Override
	public String saveColleageInfo(CollegeInfo colleageInfo) {
		if("".equals(colleageInfo.getId())) {
			if(collegeInfoDao.validateCollegeName(colleageInfo.getColleageName()) != null) 
				return "该学校名已存在！";
			colleageInfo.setId(UUID.randomUUID().toString());
			collegeInfoDao.saveCollegeInfo(colleageInfo);
		} else {
			collegeInfoDao.updateCollegeInfo(colleageInfo);
		}
		colleageInfo.setUserCategory("1");//school user
		collegeInfoDao.updateUserAdminFlag(colleageInfo);
		return null;
	}

	@Override
	public List<CollegeInfo> searchColleage(CollegeInfo colleageInfo) {
		return collegeInfoDao.searchColleage(colleageInfo);
	}

	@Override
	public CollegeInfo searchColleageById(String id) {
		return collegeInfoDao.searchColleageById(id);
	}

}
